#include "../debug-logger/sock.hpp"
#include <thread>
#include <fstream>
using namespace Logger;
int main()
{
    Sock ListenSock;
    ListenSock.Bind(8888);
    ListenSock.Listen();
    ListenSock.Setsockopt();
    int cnt = 0;
    while (true)
    {
        std::uint16_t ClientPort;
        std::string ClientIp;
        int sd = ListenSock.Accept(ClientPort, ClientIp);
        char filename[128];
        snprintf(filename, 128, "%s%d.log", "web", cnt++);
        std::cout << "start..." << std::endl;
        std::thread t1([=]() -> void
                       {
            int sock=sd;
            char buffer[1024];
            std::fstream fout(filename,std::ios_base::app|std::ios_base::out);
            while(true)
            {
                int n=recv(sock,buffer,sizeof(buffer)-1,0);
                //完成落地
                if(n>0)
                buffer[n]=0;
                else
                break;
                fout<<buffer;
            } });
        t1.detach();
    }

    return 0;
}